using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using BLL;
using DTO;

namespace QuanLiDiemCap2
{
    public partial class FrmNhapDiem : DevExpress.XtraEditors.XtraUserControl
    {
        NamHocBLL namhocbll = new NamHocBLL();
        KhoiBLL khoibll = new KhoiBLL();
        PhanLopBLL phanlopbll = new PhanLopBLL();
        KyBLL kybll = new KyBLL();
        PhanGVBLL phangvbll = new PhanGVBLL();
        public FrmNhapDiem()
        {
            InitializeComponent();
            loadDataLupNamHoc();            
            loadDataLupKy();
        }
        public void loadDataLupNamHoc()
        {
            List<NamHocDTO> listnam = namhocbll.getNamHoc();
            lupNamHoc.DataBindings.Clear();
            //binding datasource vao cho lookupedit
            lupNamHoc.Properties.DataSource = listnam;
            lupNamHoc.DataBindings.Add("EditValue", listnam, "MaNamHoc");
            //ten cot trinh bay
            lupNamHoc.Properties.DisplayMember = "TenNamHoc";//ko giong voi truong trong csdl la TenKhoi. o day la truong trong lop DTO
            //chu y neu sai ten la no ko hien thi
            //ten cot lay gia tri
            lupNamHoc.Properties.ValueMember = "MaNamHoc";
            //khi drop down xuong thi hien thi bao nhieu dong. O day ta dem so dong trong list va hien thi dung chung ay dong
            lupNamHoc.Properties.DropDownRows = listnam.Count;
            //Clear cac column da ton tai trong lookupedit neu co
            lupNamHoc.Properties.Columns.Clear();
            //tao mot cot moi de hien thi voi ten la TenKhoi--ten nay la ten truong trong KhoiDTO//neu sai se ko hien thi - Gia tri  0 la size cua truong do bang 0
            LookUpColumnInfo col = new LookUpColumnInfo("TenNamHoc", 0);//neu ko co gia tri 0 thi se ko thay duoc du lieu vi bi cot che mat
            //add vao
            lupNamHoc.Properties.Columns.Add(col);
            //  Set column widths according to their contents and resize the popup, if required.
            lupNamHoc.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lupNamHoc.Properties.SearchMode = SearchMode.AutoComplete;
            // Specify the column against which to perform the search.
            lupNamHoc.Properties.AutoSearchColumnIndex = 1;
        }
        public void loadDataLupKhoi()
        {
            List<KhoiDTO> list = khoibll.getKhoi();
            lupKhoi.DataBindings.Clear();
            //binding datasource vao cho lookupedit
            lupKhoi.Properties.DataSource = list;
            lupKhoi.DataBindings.Add("EditValue", list, "Makhoi");
            //ten cot trinh bay
            lupKhoi.Properties.DisplayMember = "Tenkhoi";//ko giong voi truong trong csdl la TenKhoi. o day la truong trong lop DTO
            //chu y neu sai ten la no ko hien thi
            //ten cot lay gia tri
            lupKhoi.Properties.ValueMember = "Makhoi";
            //khi drop down xuong thi hien thi bao nhieu dong. O day ta dem so dong trong list va hien thi dung chung ay dong
            lupKhoi.Properties.DropDownRows = list.Count;
            //Clear cac column da ton tai trong lookupedit neu co
            lupKhoi.Properties.Columns.Clear();
            //tao mot cot moi de hien thi voi ten la TenKhoi--ten nay la ten truong trong KhoiDTO//neu sai se ko hien thi - Gia tri  0 la size cua truong do bang 0
            LookUpColumnInfo col = new LookUpColumnInfo("Tenkhoi", 0);//neu ko co gia tri 0 thi se ko thay duoc du lieu vi bi cot che mat
            //add vao
            lupKhoi.Properties.Columns.Add(col);
            //  Set column widths according to their contents and resize the popup, if required.
            lupKhoi.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lupKhoi.Properties.SearchMode = SearchMode.AutoComplete;
            // Specify the column against which to perform the search.
            lupKhoi.Properties.AutoSearchColumnIndex = 1;
        }
        public void loadDataLupLop()
        {
            List<LopDTO> list = phangvbll.getLopDaPhanLop(lupNamHoc.EditValue.ToString(), lupKhoi.EditValue.ToString());
            lupLop.DataBindings.Clear();
            //binding datasource vao cho lookupedit
            lupLop.Properties.DataSource = list;
            lupLop.DataBindings.Add("EditValue", list, "Malop");
            //ten cot trinh bay
            lupLop.Properties.DisplayMember = "Tenlop";//ko giong voi truong trong csdl la TenKhoi. o day la truong trong lop DTO
            //chu y neu sai ten la no ko hien thi
            //ten cot lay gia tri
            lupLop.Properties.ValueMember = "Malop";
            //khi drop down xuong thi hien thi bao nhieu dong. O day ta dem so dong trong list va hien thi dung chung ay dong
            lupLop.Properties.DropDownRows = list.Count;
            //Clear cac column da ton tai trong lookupedit neu co
            lupLop.Properties.Columns.Clear();
            //tao mot cot moi de hien thi voi ten la TenKhoi--ten nay la ten truong trong KhoiDTO//neu sai se ko hien thi - Gia tri  0 la size cua truong do bang 0
            LookUpColumnInfo col = new LookUpColumnInfo("Tenlop", 0);//neu ko co gia tri 0 thi se ko thay duoc du lieu vi bi cot che mat
            //add vao
            lupLop.Properties.Columns.Add(col);
        }
        public void loadDataLupKy()
        {
            List<KyDTO> list = kybll.getKy();
            lupKy.DataBindings.Clear();
            //binding datasource vao cho lookupedit
            lupKy.Properties.DataSource = list;
            lupKy.DataBindings.Add("EditValue", list, "Maky");
            //ten cot trinh bay
            lupKy.Properties.DisplayMember = "Tenky";//ko giong voi truong trong csdl la TenKhoi. o day la truong trong lop DTO
            //chu y neu sai ten la no ko hien thi
            //ten cot lay gia tri
            lupKy.Properties.ValueMember = "Maky";
            //khi drop down xuong thi hien thi bao nhieu dong. O day ta dem so dong trong list va hien thi dung chung ay dong
            lupKy.Properties.DropDownRows = list.Count;
            //Clear cac column da ton tai trong lookupedit neu co
            lupKy.Properties.Columns.Clear();
            //tao mot cot moi de hien thi voi ten la TenKhoi--ten nay la ten truong trong KhoiDTO//neu sai se ko hien thi - Gia tri  0 la size cua truong do bang 0
            LookUpColumnInfo col = new LookUpColumnInfo("Tenky", 0);//neu ko co gia tri 0 thi se ko thay duoc du lieu vi bi cot che mat
            //add vao
            lupKy.Properties.Columns.Add(col);
            //  Set column widths according to their contents and resize the popup, if required.
            lupKy.Properties.BestFitMode = BestFitMode.BestFitResizePopup;

            // Enable auto completion search mode.
            lupKy.Properties.SearchMode = SearchMode.AutoComplete;
            // Specify the column against which to perform the search.
            lupKy.Properties.AutoSearchColumnIndex = 1;
        }
        public void loadDataLupmonhoc()
        {
            List<MonDTO> list = phangvbll.getMonHocCuaKhoi(lupNamHoc.EditValue.ToString(), lupKhoi.EditValue.ToString());
            lupMonHoc.DataBindings.Clear();
            //binding datasource vao cho lookupedit
            lupMonHoc.Properties.DataSource = list;
            lupMonHoc.DataBindings.Add("EditValue", list, "MaMonHoc");
            //ten cot trinh bay
            lupMonHoc.Properties.DisplayMember = "TenMonHoc";//ko giong voi truong trong csdl la TenKhoi. o day la truong trong lop DTO
            //chu y neu sai ten la no ko hien thi
            //ten cot lay gia tri
            lupMonHoc.Properties.ValueMember = "MaMonHoc";
            //khi drop down xuong thi hien thi bao nhieu dong. O day ta dem so dong trong list va hien thi dung chung ay dong
            lupMonHoc.Properties.DropDownRows = list.Count;
            //Clear cac column da ton tai trong lookupedit neu co
            lupMonHoc.Properties.Columns.Clear();
            //tao mot cot moi de hien thi voi ten la TenKhoi--ten nay la ten truong trong KhoiDTO//neu sai se ko hien thi - Gia tri  0 la size cua truong do bang 0
            LookUpColumnInfo col = new LookUpColumnInfo("TenMonHoc", 0);//neu ko co gia tri 0 thi se ko thay duoc du lieu vi bi cot che mat
            //add vao
            lupMonHoc.Properties.Columns.Add(col);
        }
        private void lupKhoi_EditValueChanged(object sender, EventArgs e)
        {
            string mystring = lupKhoi.EditValue.ToString();
            lupKhoi.EditValue = mystring;
            loadDataLupLop();
            loadDataLupmonhoc();
            
        }

        private void lupNamHoc_EditValueChanged(object sender, EventArgs e)
        {
            lupNamHoc.EditValue = lupNamHoc.EditValue.ToString();
            loadDataLupKhoi();
        }

        private void lupLop_EditValueChanged(object sender, EventArgs e)
        {
            lupLop.EditValue = lupLop.EditValue.ToString();
            
        }

        private void lupKy_EditValueChanged(object sender, EventArgs e)
        {
            lupKy.EditValue = lupKy.EditValue.ToString();
        }

        private void lupMon_EditValueChanged(object sender, EventArgs e)
        {
            lupMonHoc.EditValue = lupMonHoc.EditValue.ToString();
        }
    }
}
